﻿using System.Collections.Generic;
using System.Data.SqlClient;
using com.fukefu.sql;

namespace com.fukefu.tools
{
    public class UserCollection
    {
        Queue<User> queue = new Queue<User>();

        public UserCollection(Site site)
        {
            LoadUser(site);
        }
        //加载所有用户信息
        private void LoadUser(Site site)
        {
            SqlServerOperate sql = new SqlServerOperate();
            SqlDataReader re = sql.Query("select * from [_site_账户] where wid='" + site.Wid + "' and  flag=1");
            while (re.Read())
            {
                //加入队列
                queue.Enqueue(new User(re["uid"].ToString(), re["user"].ToString(), re["pass"].ToString(), site.Wid));
            }
            re.Close();
            sql.Close();
        }
        //获取用户数量属性
        public int Count
        {
            get { return queue.Count; }
        }
        //获取用户
        public User Get()
        {
            if (queue.Count > 0)
            {
                return queue.Dequeue();
            }
            return null;
        }
    }
}
